package com.xgpro.common.websocket;

import com.xgpro.common.results.ResponseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName WebSocketController
 * @Author: LiKai
 * @Date: 2019-09-07 11:23
 * @Version 1.0
 * @Description 用来返回前端的websocket的请求url,通过读取配置文件更改url
 */
@CrossOrigin(allowCredentials="true")
@RestController
public class WebSocketController {
    @Value("${ws.WebSocketUrl}")
    private String WebSocketUrl;

    @Value("${ws.SockJsUrl}")
    private String SockJsUrl;

    @Value("${DD_ENV.CORP_ID}")
    private String CORP_ID;


    @GetMapping("/websocket/url")
    public ResponseResult getWebSocketUrl(){

        Map<String,String> map = new HashMap<>();
        map.put("SockJsUrl",SockJsUrl);
        map.put("WebSocketUrl",WebSocketUrl);
        return ResponseResult.ok(map);
    }

    @GetMapping("/get_crop_id")
    public ResponseResult getCorpId(){

        Map<String,String> map = new HashMap<>();
        map.put("corpId",CORP_ID);
        return ResponseResult.ok(map);
    }
}
